﻿namespace _3_NovaAdmin.Domain.Abstractions;

public interface IBaseRepository<TEntity>
{
    /// <summary>
    /// 查询单条数据
    /// </summary>
    /// <param name="expression"></param>
    /// <returns></returns>
    Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> expression);

    /// <summary>
    /// 查询单条数据
    /// </summary>
    /// <param name="expression"></param>
    /// <returns></returns>
    Task<TEntity> QuerySingleData(Expression<Func<TEntity, bool>> expression, Func<TEntity, dynamic> sort);

    /// <summary>
    /// 查询单条数据
    /// </summary>
    /// <param name="expression"></param>
    /// <returns></returns>
    Task<TEntity> QuerySingleData(Expression<Func<TEntity, bool>> expression, IEnumerable<Func<TEntity, dynamic>> sorts, string sortType);

    /// <summary>
    /// 单表/视图分页查询
    /// </summary>
    /// <param name="expression"></param>
    /// <returns></returns>
    Task<Tuple<List<TEntity>, int>> QueryPageData(Expression<Func<TEntity, bool>> expression);

    /// <summary>
    /// 单表/视图分页查询
    /// </summary>
    /// <param name="expression"></param>
    /// <param name="sort"></param>
    /// <param name="order"></param>
    /// <returns></returns>
    Task<Tuple<List<TEntity>, int>> QueryPageData(Expression<Func<TEntity, bool>> expression, string sort, string order);

    /// <summary>
    /// 单表/视图分页查询
    /// </summary>
    /// <param name="expression"></param>
    /// <param name="sort"></param>
    /// <param name="sortType"></param>
    /// <returns></returns>
    Task<Tuple<List<TEntity>, int>> QueryPageData(Expression<Func<TEntity, bool>> expression, Func<TEntity, dynamic> sort, string sortType);

    /// <summary>
    /// 单表/视图分页查询
    /// </summary>
    /// <param name="expression"></param>
    /// <param name="sorts"></param>
    /// <param name="sortType"></param>
    /// <returns></returns>
    Task<Tuple<List<TEntity>, int>> QueryPageData(Expression<Func<TEntity, bool>> expression, IEnumerable<Func<TEntity, dynamic>> sorts, string sortType);

    /// <summary>
    /// 单表/视图查询=>返回指定对象
    /// </summary>
    /// <param name="expression"></param>
    /// <param name="sort"></param>
    /// <returns></returns>
    Task<IPageInfo<dynamic>> QueryPageData(Expression<Func<TEntity, bool>> expression, Func<TEntity, dynamic> sort);

    /// <summary>
    /// 根据条件查询集合
    /// </summary>
    /// <param name="expression"></param>
    /// <returns></returns>
    Task<List<TEntity>> QueryTableList(Expression<Func<TEntity, bool>> expression);

    /// <summary>
    /// 根据条件查询集合=>特定对象集合
    /// </summary>
    /// <typeparam name="TResult"></typeparam>
    /// <param name="expression"></param>
    /// <param name="result"></param>
    /// <returns></returns>
    Task<List<TResult>> QueryTableList<TResult>(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, TResult>> result);

    /// <summary>
    /// 查询数量
    /// </summary>
    /// <returns></returns>
    Task<int> QueryCount(Expression<Func<TEntity, bool>> expression);

    /// <summary>
    /// 查询是否存在
    /// </summary>
    /// <returns></returns>
    Task<bool> QueryExist(Expression<Func<TEntity, bool>> expression);
}
